extends CharacterBody2D

@onready var player = $"../Player"
@onready var anim: AnimatedSprite2D = $AnimatedSprite2D

var speed = 80

func _physics_process(delta: float) -> void:
	if not is_on_floor():
		velocity += get_gravity() * delta
	
	var direction = (player.position - self.position).normalized()
	if direction.x != 0:
		anim.play("Run")
	else:
		anim.play("Idle")
	if direction.x < 0:
		anim.flip_h = true
	else:
		anim.flip_h = false
	velocity.x = direction.x * speed
	move_and_slide()
